#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <sstream>
#include <algorithm>

using namespace std;

vector<int> Func(const vector<string>& a) {
    vector<int> a1;
    unordered_map<string, int> a2 = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    for (const auto& word : a) {
        auto it = a2.find(word);
        if (it != a2.end()) {
            a1.push_back(it->second);
        } else {
            a1.push_back(-1);
        }
    }
    return a1;
}

bool is_prime(int number) {
    if (number <= 1) return false;
    for (int i = 2; i * i <= number; ++i) {
        if (number % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string input;
    getline(cin, input);
    istringstream iss(input);
    vector<string> words;
    string word;
    while (iss >> word) {
        words.push_back(word);
    }

    vector<int> numbers = Func(words);
    if (find(numbers.begin(), numbers.end(), -1) != numbers.end()) {
        cout << "Wrong input" << endl;
        return 1;
    }

    string concatenated;
    for (int num : numbers) {
        concatenated += to_string(num);
    }
    int number = stoi(concatenated);

    if (is_prime(number)) {
        cout << number << endl;
    } else {
        int largest = 0;
        for (int i = number - 1; i > 1; --i) {
            if (is_prime(i)) {
                largest = i;
                break;
            }
        }

        int smallest = number + 1;
        while (!is_prime(smallest)) {
            ++smallest;
        }

        if (smallest - number < number - largest) {
            cout << smallest << endl;
        } else {
            cout << largest << endl;
        }
    }

    return 0;
}